#ifndef IA32BLOCKCONTEXTMANAGER_H
#define IA32BLOCKCONTEXTMANAGER_H

#include "crossbit/BlockContextManager.h"
#include "crossbit/IA32BlockContext.h"

namespace crossbit
{
    class IA32BlockContextManager : public BlockContextManager
    {
	public:
	    IA32BlockContextManager()
	    {
		for( int i = 0; i < SIZE; i ++ )
		{
		    bcList_[i] = new IA32BlockContext();
		}
	    }

	    ~IA32BlockContextManager()
	    {
		for( int i = 0; i < SIZE; i ++ )
		    delete bcList_[i];
	    }

	    void backOneInstruction( MemAddr pc )
	    {
		if( head_ != tail_ )
		{
		    BlockContext* bc = bcList_[head_];

		    if( pc == bc->getEnterPC() )
		    {
			head_ = ( head_ + SIZE - 1)%SIZE;
		    }
		    else if ( pc > bc->getEnterPC() && pc <= bc->getLastPC() )
		    {
			//empty	
		    }
		    else
		    {
			if( bc->getEnterPC() == bc->getLastPC() )
			    head_ = (head_+SIZE-1)%SIZE;
		    }
		}
	    }

	private:
	    //add member here
    };
}

#endif //IA32BLOCKCONTEXTMANAGER_H
